package com.group7.mall.controller;

import com.group7.mall.bean.Result;
import com.group7.mall.dto.*;
import com.group7.mall.entity.TbBrowsingHistory;
import com.group7.mall.entity.TbGoods;
import com.group7.mall.entity.TbSeller;
import com.group7.mall.resp.UserGoodsPageResponse;
import com.group7.mall.req.UserGoodsPageRequest;
import com.group7.mall.service.UserGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("user-goods")
@Slf4j
//@Api(tags = "用户Controller")
public class CustomerGoodsController {

    @Resource
    private UserGoodsService userGoodsService;

    @PostMapping("query-user-browsing-history")
    public Result<UserGoodsPageResponse<GoodsPreviewDto>> queryUserBrowsingHistory(@RequestBody UserGoodsPageRequest userGoodsPageRequest) {
        return Result.ok(userGoodsService.queryUserBrowsingHistory(userGoodsPageRequest));
    }

    @PostMapping("show-store")
    public Result<StoreDto> showStore(@RequestBody TbSeller tbSeller) {
        return Result.ok(userGoodsService.showStore(tbSeller));
    }

    /**
     * 分页根据商品种类、排序方式等查询商品
     *
     * @param userGoodsPageRequest 分页请求
     * @return 分页对象
     */
    @PostMapping("show-recommended-goods")
    public Result<UserGoodsPageResponse<GoodsPreviewDto>> showAllGoodsByTurnover(@RequestBody UserGoodsPageRequest userGoodsPageRequest) {
        return Result.ok(userGoodsService.queryGoodsPreviewByPage(userGoodsPageRequest));
    }

//    /**
//     * 添加商品
//     * @param tbGoods 商品
//     * @return 商品
//     */
//    @PostMapping("addGoods")
//    public Result<TbGoods> addGoods(@RequestBody TbGoods tbGoods) {
//        System.out.println(tbGoods.toString());
//        return Result.ok(this.goodsService.insert(tbGoods));
//    }

    /**
     * 展示指定商品详情
     *
     * @param tbGoods 商品对象
     * @return 商品详情对象
     */
    @PostMapping("show-goods-detail")
    public Result<UserGoodsDetailsDto> showGoodsDetail(@RequestBody TbGoods tbGoods) {
        return Result.ok(this.userGoodsService.showGoodsDetail(tbGoods.getGoodsId()));
    }

    @PostMapping("show-goods-type")
    public Result<GoodsTypeDto> showGoodsType(@RequestBody TbGoods tbGoods) {
        return Result.ok(this.userGoodsService.showGoodsAllType(tbGoods.getGoodsId()));
    }

    @PostMapping("add-click-count")
    public Result<String> addClickCount(@RequestBody TbBrowsingHistory tbBrowsingHistory) {
        userGoodsService.addClickCount(tbBrowsingHistory);
        return Result.ok("商品点击量+1成功");
    }

    @PostMapping("search-in-box")
    public Result<String> searchInBox(@RequestBody TbGoods tbGoods) {
        return Result.ok(userGoodsService.searchInBox(tbGoods.getGoodsInfo()));
    }
    // 2.根据关键词及条件搜索商品（条件：默认、价格、销量、好评等）

    // 3.根据图片查找相似商品

    // 4.根据条件查找店铺所有商品（条件：默认、价格、销量等）

}
